/**
 * Class Fragment
 * Fragments are used to create а page in other page
 * Example:
 * see Page class
 */
Fragment = (function(_super){

	__extends(Fragment, _super);
	/**
	 * Fragment constructor
	 * @param context {Page} parent Page
	 * @constructor
	 */
    function Fragment(context){
        Fragment.__super__.constructor.call(this, context);
        this.userIScroll = false;
        this.isCurrent = false;
    }
	/**
	 * Overwrite set content view to add iscroll options
	 * @param view {String|View|HTMLElement} id, html element or view
	 */
    Fragment.prototype.setContentView = function(view){
        Fragment.__super__.setContentView.call(this, view);
        if(!this.userIScroll) return;
        var scroll = this.view.select(".content", true);
        this.scroll = new iScroll(scroll, {
            hideScrollbar: true
        });
    };
	/**
	 * Create and return title bar form html with class "title-bar" form fragment view
	 * or form view argument
	 * @param [view] {String|View|HTMLElement} id, html element or view
	 * @returns {TitleBar}
	 */
    Fragment.prototype.getTitle = function(view) {
        return this.title = new TitleBar(view || this.view.element.querySelector('.title-bar'));
    };
	/**
	 * Get Fragment context
	 * @returns {Page} Fragment context
	 */
	Fragment.prototype.getContext = function(){
		return this.context;
	};
	/**
	 * Overwrite before Show to reset iscroll if we have one
	 * @param [intent] {Intent} intent that we show this element
	 */
    Fragment.prototype.beforeShow = function(intent){
        if(!this.userIScroll) return;
        this.scroll.scrollTo(0, 0);
    };
	/**
	 * Overwrite on Show to refresh iscroll if we have one and set isCurrent to true
	 * @param [intent] {Intent} intent that we show this element
	 */
    Fragment.prototype.onShow = function(intent){
        var _this = this;
        this.isCurrent = true;
        if(!this.userIScroll) return;
        setTimeout(function(){
            _this.scroll.refresh();
        },1);
    };
	/**
	 * Overwrite on Hide to set isCurrent to false because page is not current now
	 * @param [intent] {Intent} intent that we hide this element
	 */
    Fragment.prototype.onHide = function(intent){
        Fragment.__super__.onHide.call(this, intent);
        this.isCurrent = false;
    };

    return Fragment;

})(Base);